<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="generator" content="quarto-1.7.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>datasummary – modelsummary: Data and Model Summaries in R</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
  width: 0.8em;
  margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 
  vertical-align: middle;
}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
  }
pre.numberSource { margin-left: 3em;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>

<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../site_libs/clipboard/clipboard.min.js"></script>
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../site_libs/quarto-search/fuse.min.js"></script>
<script src="../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../">
<link href="../man/datasummary_skim.html" rel="next">
<link href="../man/modelplot.html" rel="prev">
<script src="../site_libs/quarto-html/quarto.js" type="module"></script>
<script src="../site_libs/quarto-html/tabsets/tabsets.js" type="module"></script>
<script src="../site_libs/quarto-html/popper.min.js"></script>
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../site_libs/quarto-html/anchor.min.js"></script>
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../site_libs/quarto-html/quarto-syntax-highlighting-37eea08aefeeee20ff55810ff984fec1.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../site_libs/bootstrap/bootstrap-555d7fa6eb067a0c9d334ac7ef1a20f4.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light"><script id="quarto-search-options" type="application/json">{
  "location": "navbar",
  "copy-button": false,
  "collapse-after": 3,
  "panel-placement": "end",
  "type": "overlay",
  "limit": 50,
  "keyboard-shortcut": [
    "f",
    "/",
    "s"
  ],
  "show-item-context": false,
  "language": {
    "search-no-results-text": "No results",
    "search-matching-documents-text": "matching documents",
    "search-copy-link-title": "Copy link to search",
    "search-hide-matches-text": "Hide additional matches",
    "search-more-match-text": "more match in this document",
    "search-more-matches-text": "more matches in this document",
    "search-clear-button-title": "Clear",
    "search-text-placeholder": "",
    "search-detached-cancel-button-title": "Cancel",
    "search-submit-button-title": "Submit",
    "search-label": "Search"
  }
}</script>
</head>
<body class="nav-sidebar floating nav-fixed quarto-light">

<div id="quarto-search-results"></div>
  <header id="quarto-header" class="headroom fixed-top"><nav class="navbar navbar-expand-lg " data-bs-theme="dark"><div class="navbar-container container-fluid">
      <div class="navbar-brand-container mx-auto">
    <a class="navbar-brand" href="../index.html">
    <span class="navbar-title">modelsummary: Data and Model Summaries in R</span>
    </a>
  </div>
            <div id="quarto-search" class="" title="Search"></div>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
  <span class="navbar-toggler-icon"></span>
</button>
          <div class="collapse navbar-collapse" id="navbarCollapse">
            <ul class="navbar-nav navbar-nav-scroll ms-auto">
<li class="nav-item">
    <a class="nav-link active" href="../vignettes/get_started.html" aria-current="page"> 
<span class="menu-text">Get started</span></a>
  </li>  
  <li class="nav-item compact">
    <a class="nav-link" href="https://github.com/vincentarelbundock/modelsummary/"> <i class="bi bi-github" role="img" aria-label="modelsummary GitHub">
</i> 
<span class="menu-text"></span></a>
  </li>  
</ul>
</div> <!-- /navcollapse -->
            <div class="quarto-navbar-tools">
</div>
      </div> <!-- /container-fluid -->
    </nav><nav class="quarto-secondary-nav"><div class="container-fluid d-flex">
      <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
        <i class="bi bi-layout-text-sidebar-reverse"></i>
      </button>
        <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="../man/modelsummary.html">Functions</a></li><li class="breadcrumb-item"><a href="../man/datasummary.html"><code>datasummary</code></a></li></ol></nav>
        <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">      
        </a>
    </div>
  </nav></header><!-- content --><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
  <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto"><div class="sidebar-menu-container"> 
    <ul class="list-unstyled mt-1">
<li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../vignettes/get_started.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Getting started</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../vignettes/datasummary.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Data Summaries</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../vignettes/modelsummary.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Model Summaries</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../vignettes/modelplot.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Model Plots</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../vignettes/modelsummary_extension.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Custom</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../vignettes/appearance.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Themes and Styles</span></a>
  </div>
</li>
        <li class="sidebar-item sidebar-item-section">
      <div class="sidebar-item-container"> 
            <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
 <span class="menu-text">Functions</span></a>
          <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
            <i class="bi bi-chevron-right ms-2"></i>
          </a> 
      </div>
      <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/modelsummary.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>modelsummary</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/modelplot.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>modelplot</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/datasummary.html" class="sidebar-item-text sidebar-link active">
 <span class="menu-text"><code>datasummary</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/datasummary_skim.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>datasummary_skim</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/datasummary_balance.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>datsummary_balance</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/datasummary_crosstab.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>datasummary_crosstab</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/datasummary_correlation.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>datasummary_correlation</code></span></a>
  </div>
</li>
          <li class="sidebar-item sidebar-item-section">
      <div class="sidebar-item-container"> 
            <a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" role="navigation" aria-expanded="false">
 <span class="menu-text">Formatting</span></a>
          <a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" role="navigation" aria-expanded="false" aria-label="Toggle section">
            <i class="bi bi-chevron-right ms-2"></i>
          </a> 
      </div>
      <ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth2 ">
<li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_decimal.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_decimal</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_equivalence.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_equivalence</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_sci.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_sci</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_significant.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_significant</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_sprintf.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_sprintf</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_statistic.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_statistic</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/fmt_term.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>fmt_term</code></span></a>
  </div>
</li>
      </ul>
</li>
          <li class="sidebar-item sidebar-item-section">
      <div class="sidebar-item-container"> 
            <a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" role="navigation" aria-expanded="false">
 <span class="menu-text">Utilities</span></a>
          <a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" role="navigation" aria-expanded="false" aria-label="Toggle section">
            <i class="bi bi-chevron-right ms-2"></i>
          </a> 
      </div>
      <ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth2 ">
<li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/get_estimates.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>get_estimates</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/get_gof.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>get_gof</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/coef_rename.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>coef_rename</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/dvnames.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>dvnames</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/gof_map.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>gof_map</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/datasummary_correlation_format.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>datasummary_correlation_format</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/config_modelsummary.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>config_modelsummary</code></span></a>
  </div>
</li>
          <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../man/update_modelsummary.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text"><code>update_modelsummary</code></span></a>
  </div>
</li>
      </ul>
</li>
      </ul>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../NEWS.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">News</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../LICENSE.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">License</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="../CITATION.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Citation</span></a>
  </div>
</li>
    </ul>
</div>
</nav><div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
<!-- margin-sidebar -->
    <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
        <nav id="TOC" role="doc-toc" class="toc-active"><h2 id="toc-title">On this page</h2>
   
  <ul>
<li>
<a href="#summary-tables-using-2-sided-formulae-crosstabs-frequencies-table-1s-and-more." id="toc-summary-tables-using-2-sided-formulae-crosstabs-frequencies-table-1s-and-more." class="nav-link active" data-scroll-target="#summary-tables-using-2-sided-formulae-crosstabs-frequencies-table-1s-and-more.">Summary tables using 2-sided formulae: crosstabs, frequencies, table 1s and more.</a>
  <ul class="collapse">
<li><a href="#description" id="toc-description" class="nav-link" data-scroll-target="#description">Description</a></li>
  <li><a href="#usage" id="toc-usage" class="nav-link" data-scroll-target="#usage">Usage</a></li>
  <li><a href="#arguments" id="toc-arguments" class="nav-link" data-scroll-target="#arguments">Arguments</a></li>
  <li><a href="#details" id="toc-details" class="nav-link" data-scroll-target="#details">Details</a></li>
  <li><a href="#version-2.0.0-kableextra-and-tinytable" id="toc-version-2.0.0-kableextra-and-tinytable" class="nav-link" data-scroll-target="#version-2.0.0-kableextra-and-tinytable">Version 2.0.0, kableExtra, and tinytable</a></li>
  <li><a href="#global-options" id="toc-global-options" class="nav-link" data-scroll-target="#global-options">Global Options</a></li>
  <li><a href="#latex-preamble" id="toc-latex-preamble" class="nav-link" data-scroll-target="#latex-preamble">LaTeX preamble</a></li>
  <li><a href="#examples" id="toc-examples" class="nav-link" data-scroll-target="#examples">Examples</a></li>
  </ul>
</li>
  </ul></nav>
    </div>
<!-- main -->
<main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="../man/modelsummary.html">Functions</a></li><li class="breadcrumb-item"><a href="../man/datasummary.html"><code>datasummary</code></a></li></ol></nav></header><section id="summary-tables-using-2-sided-formulae-crosstabs-frequencies-table-1s-and-more." class="level2 unnumbered"><h2 class="unnumbered anchored" data-anchor-id="summary-tables-using-2-sided-formulae-crosstabs-frequencies-table-1s-and-more.">Summary tables using 2-sided formulae: crosstabs, frequencies, table 1s and more.</h2>
<section id="description" class="level3"><h3 class="anchored" data-anchor-id="description">Description</h3>
<p><code>datasummary</code> can use any summary function which produces one numeric or character value per variable. The examples section of this documentation shows how to define custom summary functions.</p>
<p><code>modelsummary</code> also supplies several shortcut summary functions which can be used in <code><a href="https://modelsummary.com/man/datasummary.html">datasummary()</a></code> formulas: Min, Max, Mean, Median, Var, SD, NPercent, NUnique, Ncol, P0, P25, P50, P75, P100.</p>
<p>See the Details and Examples sections below, and the vignettes on the <code>modelsummary</code> website:</p>
<ul>
<li>
<p>https://modelsummary.com/</p>
</li>
<li>
<p>https://modelsummary.com/vignettes/datasummary.html</p>
</li>
</ul></section><section id="usage" class="level3"><h3 class="anchored" data-anchor-id="usage">Usage</h3>
<pre><code class="language-R">datasummary(
  formula,
  data,
  output = getOption("modelsummary_output", default = "default"),
  fmt = 2,
  title = getOption("modelsummary_title", default = NULL),
  notes = getOption("modelsummary_notes", default = NULL),
  align = getOption("modelsummary_align", default = NULL),
  add_columns = getOption("modelsummary_add_columns", default = NULL),
  add_rows = getOption("modelsummary_add_rows", default = NULL),
  sparse_header = getOption("modelsummary_sparse_header", default = TRUE),
  escape = getOption("modelsummary_escape", default = TRUE),
  ...
)
</code></pre>
</section><section id="arguments" class="level3"><h3 class="anchored" data-anchor-id="arguments">Arguments</h3>
<table>
<tbody><tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="formula">formula</code>
</td>
<td>
A two-sided formula to describe the table: rows ~ columns. See the Examples section for a mini-tutorial and the Details section for more resources. Grouping/nesting variables can appear on both sides of the formula, but all summary functions must be on one side.
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="data">data</code>
</td>
<td>
A data.frame (or tibble)
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="output">output</code>
</td>
<td>
<p>filename or object type (character string)</p>
<ul>
<li>
<p>Supported filename extensions: .docx, .html, .tex, .md, .txt, .csv, .xlsx, .png, .jpg</p>
</li>
<li>
<p>Supported object types: "default", "html", "markdown", "latex", "latex_tabular", "typst", "data.frame", "tinytable", "gt", "kableExtra", "huxtable", "flextable", "DT", "jupyter". The "modelsummary_list" value produces a lightweight object which can be saved and fed back to the <code>modelsummary</code> function.</p>
</li>
<li>
<p>The "default" output format can be set to "tinytable", "kableExtra", "gt", "flextable", "huxtable", "DT", or "markdown"</p>
<ul>
<li>
<p>If the user does not choose a default value, the packages listed above are tried in sequence.</p>
</li>
<li>
<p>Session-specific configuration: <code>options(“modelsummary_factory_default” = “gt”)</code></p>
</li>
<li>
<p>Persistent configuration: <code>config_modelsummary(output = “markdown”)</code></p>
</li>
</ul>
</li>
<li>
<p>Warning: Users should not supply a file name to the <code>output</code> argument if they intend to customize the table with external packages. See the ‘Details’ section.</p>
</li>
<li>
<p>LaTeX compilation requires the <code>booktabs</code> and <code>siunitx</code> packages, but <code>siunitx</code> can be disabled or replaced with global options. See the ‘Details’ section.</p>
</li>
</ul>
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="fmt">fmt</code>
</td>
<td>
<p>how to format numeric values: integer, user-supplied function, or <code>modelsummary</code> function.</p>
<ul>
<li>
<p>Integer: Number of decimal digits</p>
</li>
<li>
<p>User-supplied functions:</p>
<ul>
<li>
<p>Any function which accepts a numeric vector and returns a character vector of the same length.</p>
</li>
</ul>
</li>
<li>
<p><code>modelsummary</code> functions:</p>
<ul>
<li>
<p><code>fmt = fmt_significant(2)</code>: Two significant digits (at the term-level)</p>
</li>
<li>
<p><code>fmt = fmt_sprintf(“%.3f”)</code>: See <code><a href="https://rdrr.io/r/base/sprintf.html">?sprintf</a></code></p>
</li>
<li>
<p><code>fmt = fmt_identity()</code>: unformatted raw values</p>
</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="title">title</code>
</td>
<td>
string. Cross-reference labels should be added with Quarto or Rmarkdown chunk options when applicable. When saving standalone LaTeX files, users can add a label such as <code style="white-space: pre;">\label{tab:mytable}</code> directly to the title string, while also specifying <code>escape=FALSE</code>.
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="notes">notes</code>
</td>
<td>
list or vector of notes to append to the bottom of the table.
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="align">align</code>
</td>
<td>
<p>A string with a number of characters equal to the number of columns in the table (e.g., <code>align = “lcc”</code>). Valid characters: l, c, r, d.</p>
<ul>
<li>
<p>"l": left-aligned column</p>
</li>
<li>
<p>"c": centered column</p>
</li>
<li>
<p>"r": right-aligned column</p>
</li>
<li>
<p>"d": dot-aligned column. For LaTeX/PDF output, this option requires at least version 3.0.25 of the siunitx LaTeX package. See the LaTeX preamble help section below for commands to insert in your LaTeX preamble.</p>
</li>
</ul>
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="add_columns">add_columns</code>
</td>
<td>
a data.frame (or tibble) with the same number of rows as your main table.
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="add_rows">add_rows</code>
</td>
<td>
<p>a data.frame (or tibble) with the same number of columns as your main table. By default, rows are appended to the bottom of the table. Positions can be defined using integers. In the <code><a href="https://modelsummary.com/man/modelsummary.html">modelsummary()</a></code> function (only), you can also use string shortcuts: "coef_start", "coef_end", "gof_start", "gof_end"</p>
<ul>
<li>
<p><code>attr(new_rows, 1:2)</code></p>
</li>
<li>
<p><code>attr(new_rows, “gof_start”)</code> See Examples section below.</p>
</li>
</ul>
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="sparse_header">sparse_header</code>
</td>
<td>
TRUE or FALSE. TRUE eliminates column headers which have a unique label across all columns, except for the row immediately above the data. FALSE keeps all headers. The order in which terms are entered in the formula determines the order in which headers appear. For example, <code>x~mean*z</code> will print the <code>mean</code>-related header above the <code>z</code>-related header.’
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="escape">escape</code>
</td>
<td>
boolean TRUE escapes or substitutes LaTeX/HTML characters which could prevent the file from compiling/displaying. <code>TRUE</code> escapes all cells, captions, and notes. Users can have more fine-grained control by setting <code>escape=FALSE</code> and using an external command such as: <code>modelsummary(model, “latex”) |&gt; tinytable::format_tt(tab, j=1:5, escape=TRUE)</code>
</td>
</tr>
<tr>
<td style="white-space: collapse; font-family: monospace; vertical-align: top">
<code id="...">…</code>
</td>
<td>
all other arguments are passed through to the table-making functions tinytable::tt, kableExtra::kbl, gt::gt, DT::datatable, etc. depending on the <code>output</code> argument. This allows users to pass arguments directly to <code>datasummary</code> in order to affect the behavior of other functions behind the scenes.
</td>
</tr>
</tbody></table></section><section id="details" class="level3"><h3 class="anchored" data-anchor-id="details">Details</h3>
<p>Visit the ‘modelsummary’ website for more usage examples: https://modelsummary.com</p>
<p>The ‘datasummary’ function is a thin wrapper around the ‘tabular’ function from the ‘tables’ package. More details about table-making formulas can be found in the ‘tables’ package documentation: ?tables::tabular</p>
<p>Hierarchical or "nested" column labels are only available for these output formats: tinytable, kableExtra, gt, html, rtf, and LaTeX. When saving tables to other formats, nested labels will be combined to a "flat" header.</p>
</section><section id="version-2.0.0-kableextra-and-tinytable" class="level3"><h3 class="anchored" data-anchor-id="version-2.0.0-kableextra-and-tinytable">Version 2.0.0, kableExtra, and tinytable</h3>
<p>Since version 2.0.0, <code>modelsummary</code> uses <code>tinytable</code> as its default table-drawing backend. Learn more at: https://vincentarelbundock.github.io/tinytable/",</p>
<p>Revert to <code>kableExtra</code> for one session:</p>
<p><code>options(modelsummary_factory_default = ‘kableExtra’)</code> <code>options(modelsummary_factory_latex = ‘kableExtra’)</code> <code>options(modelsummary_factory_html = ‘kableExtra’)</code></p>
</section><section id="global-options" class="level3"><h3 class="anchored" data-anchor-id="global-options">Global Options</h3>
<p>The behavior of <code>modelsummary</code> can be modified by setting global options. In particular, most of the arguments for most of the package’s functions cna be set using global options. For example:</p>
<ul>
<li>
<p><code>options(modelsummary_output = “modelsummary_list”)</code></p>
</li>
<li>
<p><code>options(modelsummary_statistic = ‘({conf.low}, {conf.high})’)</code></p>
</li>
<li>
<p><code>options(modelsummary_stars = TRUE)</code></p>
</li>
</ul>
<p>Options not specific to given arguments are listed below.</p>
<h4 class="anchored">
Model labels: default column names
</h4>
<p>These global option changes the style of the default column headers:</p>
<ul>
<li>
<p><code>options(modelsummary_model_labels = “roman”)</code></p>
</li>
</ul>
<p>The supported styles are: "model", "arabic", "letters", "roman", "(arabic)", "(letters)", "(roman)"</p>
<h4 class="anchored">
Table-making packages
</h4>
<p><code>modelsummary</code> supports 6 table-making packages: <code>tinytable</code>, <code>kableExtra</code>, <code>gt</code>, <code>flextable</code>, <code>huxtable</code>, and <code>DT</code>. Some of these packages have overlapping functionalities. To change the default backend used for a specific file format, you can use ’ the <code>options</code> function:</p>
<p><code>options(modelsummary_factory_html = ‘kableExtra’)</code> <code>options(modelsummary_factory_word = ‘huxtable’)</code> <code>options(modelsummary_factory_png = ‘gt’)</code> <code>options(modelsummary_factory_latex = ‘gt’)</code> <code>options(modelsummary_factory_latex_tabular = ‘kableExtra’)</code></p>
<h4 class="anchored">
Table themes
</h4>
<p>Change the look of tables in an automated and replicable way, using the <code>modelsummary</code> theming functionality. See the vignette: https://modelsummary.com/vignettes/appearance.html</p>
<ul>
<li>
<p><code>modelsummary_theme_gt</code></p>
</li>
<li>
<p><code>modelsummary_theme_kableExtra</code></p>
</li>
<li>
<p><code>modelsummary_theme_huxtable</code></p>
</li>
<li>
<p><code>modelsummary_theme_flextable</code></p>
</li>
<li>
<p><code>modelsummary_theme_dataframe</code></p>
</li>
</ul>
<h4 class="anchored">
Model extraction functions
</h4>
<p><code>modelsummary</code> can use two sets of packages to extract information from statistical models: the <code>easystats</code> family (<code>performance</code> and <code>parameters</code>) and <code>broom</code>. By default, it uses <code>easystats</code> first and then falls back on <code>broom</code> in case of failure. You can change the order of priorities or include goodness-of-fit extracted by <em>both</em> packages by setting:</p>
<p><code>options(modelsummary_get = “easystats”)</code></p>
<p><code>options(modelsummary_get = “broom”)</code></p>
<p><code>options(modelsummary_get = “all”)</code></p>
<p>The "all" option (default) means easystats then broom.</p>
<h4 class="anchored">
Formatting numeric entries
</h4>
<p>By default, LaTeX tables enclose all numeric entries in the <code style="white-space: pre;"></code> command from the siunitx package. To prevent this behavior, or to enclose numbers in dollar signs (for LaTeX math mode), users can call:</p>
<p><code>options(modelsummary_format_numeric_latex = “plain”)</code></p>
<p><code>options(modelsummary_format_numeric_latex = “mathmode”)</code></p>
<p>A similar option can be used to display numerical entries using MathJax in HTML tables:</p>
<p><code>options(modelsummary_format_numeric_html = “mathjax”)</code></p>
</section><section id="latex-preamble" class="level3"><h3 class="anchored" data-anchor-id="latex-preamble">LaTeX preamble</h3>
<p>When creating LaTeX via the <code>tinytable</code> backend (default in version 2.0.0 and later), it is useful to include the following commands in the LaTeX preamble of your documents. These commands are automatically added to the preamble when compiling Rmarkdown or Quarto documents, except when the <code><a href="https://modelsummary.com/man/modelsummary.html">modelsummary()</a></code> calls are cached.</p>
<div class="sourceCode latex">
<pre>\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage[normalem]{ulem}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{siunitx}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
</pre>
</div>
</section><section id="examples" class="level3"><h3 class="anchored" data-anchor-id="examples">Examples</h3>
<div class="cell">
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="st"><a href="https://modelsummary.com">"modelsummary"</a></span><span class="op">)</span></span>
<span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://modelsummary.com">modelsummary</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># The left-hand side of the formula describes rows, and the right-hand side</span></span>
<span><span class="co"># describes columns. This table uses the "mpg" variable as a row and the "mean"</span></span>
<span><span class="co"># function as a column:</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">mpg</span> <span class="op">~</span> <span class="va">mean</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_wawlpiz826rbltqxcrf8(i, j, css_id) {
          var table = document.getElementById("tinytable_wawlpiz826rbltqxcrf8");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_wawlpiz826rbltqxcrf8(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_wawlpiz826rbltqxcrf8");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '1', j: 1 },  ], css_id: 'tinytable_css_6xnmhbg0apd6j8ep8g4q',}, 
          { positions: [ { i: '0', j: 1 },  ], css_id: 'tinytable_css_c4kxa6ucekj664frwp9l',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_q1ikvg34f6opptxebylt',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_oegbk9xism4r1u04hqqi',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_wawlpiz826rbltqxcrf8(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_6xnmhbg0apd6j8ep8g4q, .table th.tinytable_css_6xnmhbg0apd6j8ep8g4q { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_c4kxa6ucekj664frwp9l, .table th.tinytable_css_c4kxa6ucekj664frwp9l { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_q1ikvg34f6opptxebylt, .table th.tinytable_css_q1ikvg34f6opptxebylt { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_oegbk9xism4r1u04hqqi, .table th.tinytable_css_oegbk9xism4r1u04hqqi { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_wawlpiz826rbltqxcrf8" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mean</th>
              </tr></thead>
<tbody><tr>
<td data-row="1" data-col="0">mpg</td>
                  <td data-row="1" data-col="1">20.09</td>
                </tr></tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># This table uses the "mean" function as a row and the "mpg" variable as a column:</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">mean</span> <span class="op">~</span> <span class="va">mpg</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_pmgliji6vlc1tjbkd9w9(i, j, css_id) {
          var table = document.getElementById("tinytable_pmgliji6vlc1tjbkd9w9");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_pmgliji6vlc1tjbkd9w9(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_pmgliji6vlc1tjbkd9w9");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '1', j: 1 },  ], css_id: 'tinytable_css_3y2v2rknh95vjxymj6u9',}, 
          { positions: [ { i: '0', j: 1 },  ], css_id: 'tinytable_css_vpu5sskdv4w7cbdiby8j',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_iko4hsbg0gggmyzwj75y',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_ngt1xizvjsyjedvy2pm4',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_pmgliji6vlc1tjbkd9w9(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_3y2v2rknh95vjxymj6u9, .table th.tinytable_css_3y2v2rknh95vjxymj6u9 { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_vpu5sskdv4w7cbdiby8j, .table th.tinytable_css_vpu5sskdv4w7cbdiby8j { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_iko4hsbg0gggmyzwj75y, .table th.tinytable_css_iko4hsbg0gggmyzwj75y { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_ngt1xizvjsyjedvy2pm4, .table th.tinytable_css_ngt1xizvjsyjedvy2pm4 { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_pmgliji6vlc1tjbkd9w9" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mpg</th>
              </tr></thead>
<tbody><tr>
<td data-row="1" data-col="0">mean</td>
                  <td data-row="1" data-col="1">20.09</td>
                </tr></tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Display several variables or functions of the data using the "+"</span></span>
<span><span class="co"># concatenation operator. This table has 2 rows and 2 columns:</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">mean</span> <span class="op">+</span> <span class="va">sd</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_hupe1i5bhq065jfqbkhw(i, j, css_id) {
          var table = document.getElementById("tinytable_hupe1i5bhq065jfqbkhw");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_hupe1i5bhq065jfqbkhw(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_hupe1i5bhq065jfqbkhw");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '2', j: 1 }, { i: '2', j: 2 },  ], css_id: 'tinytable_css_elqnru906yj8lwbr39uv',}, 
          { positions: [ { i: '1', j: 1 }, { i: '1', j: 2 },  ], css_id: 'tinytable_css_yxjnatjlxp9zqiacf16u',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_thao5cd4xj0ex358af4e',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_txirffno791xjoics1en',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_pfca9gnv5wngfgfw2v6i',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_thrvz74tkl92hnrprjk3',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_hupe1i5bhq065jfqbkhw(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_elqnru906yj8lwbr39uv, .table th.tinytable_css_elqnru906yj8lwbr39uv { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_yxjnatjlxp9zqiacf16u, .table th.tinytable_css_yxjnatjlxp9zqiacf16u { text-align: right; }
      .table td.tinytable_css_thao5cd4xj0ex358af4e, .table th.tinytable_css_thao5cd4xj0ex358af4e { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_txirffno791xjoics1en, .table th.tinytable_css_txirffno791xjoics1en { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_pfca9gnv5wngfgfw2v6i, .table th.tinytable_css_pfca9gnv5wngfgfw2v6i { text-align: left; }
      .table td.tinytable_css_thrvz74tkl92hnrprjk3, .table th.tinytable_css_thrvz74tkl92hnrprjk3 { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_hupe1i5bhq065jfqbkhw" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mean</th>
                <th scope="col" data-row="0" data-col="2">sd</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">146.69</td>
                  <td data-row="1" data-col="2">68.56</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">20.09</td>
                  <td data-row="2" data-col="2">6.03</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Nest variables or statistics inside a "factor" variable using the "*" nesting</span></span>
<span><span class="co"># operator. This table shows the mean of "hp" and "mpg" for each value of</span></span>
<span><span class="co"># "cyl":</span></span>
<span></span>
<span><span class="va">mtcars</span><span class="op">$</span><span class="va">cyl</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html">as.factor</a></span><span class="op">(</span><span class="va">mtcars</span><span class="op">$</span><span class="va">cyl</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">cyl</span> <span class="op">*</span> <span class="va">mean</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_n90v8tdw27ftr7ukknyx(i, j, css_id) {
          var table = document.getElementById("tinytable_n90v8tdw27ftr7ukknyx");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_n90v8tdw27ftr7ukknyx(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_n90v8tdw27ftr7ukknyx");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '2', j: 2 }, { i: '2', j: 1 }, { i: '2', j: 3 },  ], css_id: 'tinytable_css_0ooeb4kcs8ops0rggb6a',}, 
          { positions: [ { i: '1', j: 1 }, { i: '1', j: 2 }, { i: '1', j: 3 },  ], css_id: 'tinytable_css_vbja5idg0xl5e4mjsnkw',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 3 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_p4u0ogykcivo0qijj0hb',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_dodm997913er12wui8e3',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_tpjq1cpztxru5rti87au',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_ebme20chx83ou3u7ksx7',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_n90v8tdw27ftr7ukknyx(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_0ooeb4kcs8ops0rggb6a, .table th.tinytable_css_0ooeb4kcs8ops0rggb6a { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_vbja5idg0xl5e4mjsnkw, .table th.tinytable_css_vbja5idg0xl5e4mjsnkw { text-align: right; }
      .table td.tinytable_css_p4u0ogykcivo0qijj0hb, .table th.tinytable_css_p4u0ogykcivo0qijj0hb { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_dodm997913er12wui8e3, .table th.tinytable_css_dodm997913er12wui8e3 { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_tpjq1cpztxru5rti87au, .table th.tinytable_css_tpjq1cpztxru5rti87au { text-align: left; }
      .table td.tinytable_css_ebme20chx83ou3u7ksx7, .table th.tinytable_css_ebme20chx83ou3u7ksx7 { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_n90v8tdw27ftr7ukknyx" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">4</th>
                <th scope="col" data-row="0" data-col="2">6</th>
                <th scope="col" data-row="0" data-col="3">8</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">82.64</td>
                  <td data-row="1" data-col="2">122.29</td>
                  <td data-row="1" data-col="3">209.21</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">26.66</td>
                  <td data-row="2" data-col="2">19.74</td>
                  <td data-row="2" data-col="3">15.10</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># If you don't want to convert your original data</span></span>
<span><span class="co"># to factors, you can use the 'Factor()'</span></span>
<span><span class="co"># function inside 'datasummary' to obtain an identical result:</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="fu"><a href="https://dmurdoch.github.io/tables/reference/RowFactor.html">Factor</a></span><span class="op">(</span><span class="va">cyl</span><span class="op">)</span> <span class="op">*</span> <span class="va">mean</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_j326hjl2wehrxads1h92(i, j, css_id) {
          var table = document.getElementById("tinytable_j326hjl2wehrxads1h92");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_j326hjl2wehrxads1h92(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_j326hjl2wehrxads1h92");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '2', j: 2 }, { i: '2', j: 1 }, { i: '2', j: 3 },  ], css_id: 'tinytable_css_z6j0op80xwl9q8gby9w0',}, 
          { positions: [ { i: '1', j: 1 }, { i: '1', j: 2 }, { i: '1', j: 3 },  ], css_id: 'tinytable_css_9f3wvbri6k9k36e9wbc4',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 3 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_1zu2tkt5xtk1ac8588vr',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_coo3qwd13xukv7ueqc11',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_ib60sc99boy9o88tgbhq',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_8t8a90reha4ab8hnceod',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_j326hjl2wehrxads1h92(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_z6j0op80xwl9q8gby9w0, .table th.tinytable_css_z6j0op80xwl9q8gby9w0 { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_9f3wvbri6k9k36e9wbc4, .table th.tinytable_css_9f3wvbri6k9k36e9wbc4 { text-align: right; }
      .table td.tinytable_css_1zu2tkt5xtk1ac8588vr, .table th.tinytable_css_1zu2tkt5xtk1ac8588vr { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_coo3qwd13xukv7ueqc11, .table th.tinytable_css_coo3qwd13xukv7ueqc11 { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_ib60sc99boy9o88tgbhq, .table th.tinytable_css_ib60sc99boy9o88tgbhq { text-align: left; }
      .table td.tinytable_css_8t8a90reha4ab8hnceod, .table th.tinytable_css_8t8a90reha4ab8hnceod { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_j326hjl2wehrxads1h92" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">4</th>
                <th scope="col" data-row="0" data-col="2">6</th>
                <th scope="col" data-row="0" data-col="3">8</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">82.64</td>
                  <td data-row="1" data-col="2">122.29</td>
                  <td data-row="1" data-col="3">209.21</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">26.66</td>
                  <td data-row="2" data-col="2">19.74</td>
                  <td data-row="2" data-col="3">15.10</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># You can nest several variables or statistics inside a factor by using</span></span>
<span><span class="co"># parentheses. This table shows the mean and the standard deviation for each</span></span>
<span><span class="co"># subset of "cyl":</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">cyl</span> <span class="op">*</span> <span class="op">(</span><span class="va">mean</span> <span class="op">+</span> <span class="va">sd</span><span class="op">)</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_ahospzg9s83ftn5cetqm(i, j, css_id) {
          var table = document.getElementById("tinytable_ahospzg9s83ftn5cetqm");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_ahospzg9s83ftn5cetqm(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_ahospzg9s83ftn5cetqm");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '-1', j: 4 }, { i: '-1', j: 5 }, { i: '-1', j: 6 },  ], css_id: 'tinytable_css_2dvml73gad6htz8jj07z',}, 
          { positions: [ { i: '2', j: 1 }, { i: '2', j: 2 }, { i: '2', j: 3 }, { i: '2', j: 4 }, { i: '2', j: 5 }, { i: '2', j: 6 },  ], css_id: 'tinytable_css_onod0avgutbhzjtyy10i',}, 
          { positions: [ { i: '1', j: 1 }, { i: '1', j: 2 }, { i: '1', j: 3 }, { i: '1', j: 4 }, { i: '1', j: 5 }, { i: '1', j: 6 },  ], css_id: 'tinytable_css_ehmrbxybabgl9g20prix',}, 
          { positions: [ { i: '-1', j: 1 }, { i: '-1', j: 2 }, { i: '-1', j: 3 },  ], css_id: 'tinytable_css_gfhojpvxi13940fc4ugo',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 }, { i: '0', j: 3 }, { i: '0', j: 4 }, { i: '0', j: 5 }, { i: '0', j: 6 },  ], css_id: 'tinytable_css_3zt7ai44oa8j6ka7mwu6',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_dmax4xv78mbrzag9d70s',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_2dxvbv1nxkskursco7mz',}, 
          { positions: [ { i: '-1', j: 0 },  ], css_id: 'tinytable_css_nd1a4sdfzjcga3271t5u',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_zqayihoomb1j58bo2qd7',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_ahospzg9s83ftn5cetqm(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_2dvml73gad6htz8jj07z, .table th.tinytable_css_2dvml73gad6htz8jj07z { text-align: right; text-align: center; border-top: solid #d3d8dc 0.1em; text-align: center; }
      .table td.tinytable_css_onod0avgutbhzjtyy10i, .table th.tinytable_css_onod0avgutbhzjtyy10i { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_ehmrbxybabgl9g20prix, .table th.tinytable_css_ehmrbxybabgl9g20prix { text-align: right; }
      .table td.tinytable_css_gfhojpvxi13940fc4ugo, .table th.tinytable_css_gfhojpvxi13940fc4ugo { text-align: right; text-align: center; border-top: solid #d3d8dc 0.1em; text-align: center; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_3zt7ai44oa8j6ka7mwu6, .table th.tinytable_css_3zt7ai44oa8j6ka7mwu6 { text-align: right; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_dmax4xv78mbrzag9d70s, .table th.tinytable_css_dmax4xv78mbrzag9d70s { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_2dxvbv1nxkskursco7mz, .table th.tinytable_css_2dxvbv1nxkskursco7mz { text-align: left; }
      .table td.tinytable_css_nd1a4sdfzjcga3271t5u, .table th.tinytable_css_nd1a4sdfzjcga3271t5u { text-align: left; text-align: center; border-top: solid #d3d8dc 0.1em; text-align: center; }
      .table td.tinytable_css_zqayihoomb1j58bo2qd7, .table th.tinytable_css_zqayihoomb1j58bo2qd7 { text-align: left; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_ahospzg9s83ftn5cetqm" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead>
<tr>
<th scope="col" align="center" colspan="1" data-row="-1" data-col="0"> </th>
<th scope="col" align="center" colspan="2" data-row="-1" data-col="1">4</th>
<th scope="col" align="center" colspan="2" data-row="-1" data-col="2">6</th>
<th scope="col" align="center" colspan="2" data-row="-1" data-col="3">8</th>
</tr>
<tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mean</th>
                <th scope="col" data-row="0" data-col="2">sd</th>
                <th scope="col" data-row="0" data-col="3">mean</th>
                <th scope="col" data-row="0" data-col="4">sd</th>
                <th scope="col" data-row="0" data-col="5">mean</th>
                <th scope="col" data-row="0" data-col="6">sd</th>
              </tr>
</thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">82.64</td>
                  <td data-row="1" data-col="2">20.93</td>
                  <td data-row="1" data-col="3">122.29</td>
                  <td data-row="1" data-col="4">24.26</td>
                  <td data-row="1" data-col="5">209.21</td>
                  <td data-row="1" data-col="6">50.98</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">26.66</td>
                  <td data-row="2" data-col="2">4.51</td>
                  <td data-row="2" data-col="3">19.74</td>
                  <td data-row="2" data-col="4">1.45</td>
                  <td data-row="2" data-col="5">15.10</td>
                  <td data-row="2" data-col="6">2.56</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Summarize all numeric variables with 'All()'</span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="fu"><a href="https://dmurdoch.github.io/tables/reference/All.html">All</a></span><span class="op">(</span><span class="va">mtcars</span><span class="op">)</span> <span class="op">~</span> <span class="va">mean</span> <span class="op">+</span> <span class="va">sd</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_376rfpuvoz6ljecl4c8a(i, j, css_id) {
          var table = document.getElementById("tinytable_376rfpuvoz6ljecl4c8a");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_376rfpuvoz6ljecl4c8a(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_376rfpuvoz6ljecl4c8a");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '10', j: 1 }, { i: '10', j: 2 },  ], css_id: 'tinytable_css_szi4qgb2nbklhitb4ju0',}, 
          { positions: [ { i: '1', j: 1 }, { i: '2', j: 1 }, { i: '4', j: 1 }, { i: '5', j: 1 }, { i: '6', j: 1 }, { i: '3', j: 1 }, { i: '8', j: 1 }, { i: '9', j: 1 }, { i: '3', j: 2 }, { i: '7', j: 1 }, { i: '1', j: 2 }, { i: '2', j: 2 }, { i: '7', j: 2 }, { i: '4', j: 2 }, { i: '5', j: 2 }, { i: '6', j: 2 }, { i: '8', j: 2 }, { i: '9', j: 2 },  ], css_id: 'tinytable_css_i749d7tuewlrlsewzcms',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_8g0rqw4tkp0puo1m00mm',}, 
          { positions: [ { i: '10', j: 0 },  ], css_id: 'tinytable_css_7jmp6wzrickd8xtp1uih',}, 
          { positions: [ { i: '1', j: 0 }, { i: '2', j: 0 }, { i: '3', j: 0 }, { i: '4', j: 0 }, { i: '5', j: 0 }, { i: '6', j: 0 }, { i: '7', j: 0 }, { i: '8', j: 0 }, { i: '9', j: 0 },  ], css_id: 'tinytable_css_vzyosjelta5hd14h5hnb',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_005dxsds4wyn3g2wfy0v',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_376rfpuvoz6ljecl4c8a(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_szi4qgb2nbklhitb4ju0, .table th.tinytable_css_szi4qgb2nbklhitb4ju0 { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_i749d7tuewlrlsewzcms, .table th.tinytable_css_i749d7tuewlrlsewzcms { text-align: right; }
      .table td.tinytable_css_8g0rqw4tkp0puo1m00mm, .table th.tinytable_css_8g0rqw4tkp0puo1m00mm { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_7jmp6wzrickd8xtp1uih, .table th.tinytable_css_7jmp6wzrickd8xtp1uih { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_vzyosjelta5hd14h5hnb, .table th.tinytable_css_vzyosjelta5hd14h5hnb { text-align: left; }
      .table td.tinytable_css_005dxsds4wyn3g2wfy0v, .table th.tinytable_css_005dxsds4wyn3g2wfy0v { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_376rfpuvoz6ljecl4c8a" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mean</th>
                <th scope="col" data-row="0" data-col="2">sd</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">mpg</td>
                  <td data-row="1" data-col="1">20.09</td>
                  <td data-row="1" data-col="2">6.03</td>
                </tr>
<tr>
<td data-row="2" data-col="0">disp</td>
                  <td data-row="2" data-col="1">230.72</td>
                  <td data-row="2" data-col="2">123.94</td>
                </tr>
<tr>
<td data-row="3" data-col="0">hp</td>
                  <td data-row="3" data-col="1">146.69</td>
                  <td data-row="3" data-col="2">68.56</td>
                </tr>
<tr>
<td data-row="4" data-col="0">drat</td>
                  <td data-row="4" data-col="1">3.60</td>
                  <td data-row="4" data-col="2">0.53</td>
                </tr>
<tr>
<td data-row="5" data-col="0">wt</td>
                  <td data-row="5" data-col="1">3.22</td>
                  <td data-row="5" data-col="2">0.98</td>
                </tr>
<tr>
<td data-row="6" data-col="0">qsec</td>
                  <td data-row="6" data-col="1">17.85</td>
                  <td data-row="6" data-col="2">1.79</td>
                </tr>
<tr>
<td data-row="7" data-col="0">vs</td>
                  <td data-row="7" data-col="1">0.44</td>
                  <td data-row="7" data-col="2">0.50</td>
                </tr>
<tr>
<td data-row="8" data-col="0">am</td>
                  <td data-row="8" data-col="1">0.41</td>
                  <td data-row="8" data-col="2">0.50</td>
                </tr>
<tr>
<td data-row="9" data-col="0">gear</td>
                  <td data-row="9" data-col="1">3.69</td>
                  <td data-row="9" data-col="2">0.74</td>
                </tr>
<tr>
<td data-row="10" data-col="0">carb</td>
                  <td data-row="10" data-col="1">2.81</td>
                  <td data-row="10" data-col="2">1.62</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Define custom summary statistics. Your custom function should accept a vector</span></span>
<span><span class="co"># of numeric values and return a single numeric or string value:</span></span>
<span></span>
<span><span class="va">minmax</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/sprintf.html">sprintf</a></span><span class="op">(</span><span class="st">"[%.2f, %.2f]"</span>, <span class="fu"><a href="https://rdrr.io/r/base/Extremes.html">min</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>, <span class="fu"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">mean_na</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op">(</span><span class="va">x</span>, na.rm <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">minmax</span> <span class="op">+</span> <span class="va">mean_na</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_6hzqtgpfqhgcdkp9um70(i, j, css_id) {
          var table = document.getElementById("tinytable_6hzqtgpfqhgcdkp9um70");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_6hzqtgpfqhgcdkp9um70(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_6hzqtgpfqhgcdkp9um70");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '2', j: 1 }, { i: '2', j: 2 },  ], css_id: 'tinytable_css_obe5bzpnw6mwwtn1ixlg',}, 
          { positions: [ { i: '1', j: 1 }, { i: '1', j: 2 },  ], css_id: 'tinytable_css_0tyws2mpvjs2t5aiw99b',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_x1cuxh695hamp5vdee4n',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_wv3yn1nug02opg2kcwl8',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_lx0x5kplcdqc6k7dd9v3',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_9bvbm5k4o2frzf3x1i3q',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_6hzqtgpfqhgcdkp9um70(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_obe5bzpnw6mwwtn1ixlg, .table th.tinytable_css_obe5bzpnw6mwwtn1ixlg { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_0tyws2mpvjs2t5aiw99b, .table th.tinytable_css_0tyws2mpvjs2t5aiw99b { text-align: right; }
      .table td.tinytable_css_x1cuxh695hamp5vdee4n, .table th.tinytable_css_x1cuxh695hamp5vdee4n { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_wv3yn1nug02opg2kcwl8, .table th.tinytable_css_wv3yn1nug02opg2kcwl8 { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_lx0x5kplcdqc6k7dd9v3, .table th.tinytable_css_lx0x5kplcdqc6k7dd9v3 { text-align: left; }
      .table td.tinytable_css_9bvbm5k4o2frzf3x1i3q, .table th.tinytable_css_9bvbm5k4o2frzf3x1i3q { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_6hzqtgpfqhgcdkp9um70" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">minmax</th>
                <th scope="col" data-row="0" data-col="2">mean_na</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">[52.00, 335.00]</td>
                  <td data-row="1" data-col="2">146.69</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">[10.40, 33.90]</td>
                  <td data-row="2" data-col="2">20.09</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># To handle missing values, you can pass arguments to your functions using</span></span>
<span><span class="co"># '*Arguments()'</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">mean</span> <span class="op">*</span> <span class="fu"><a href="https://dmurdoch.github.io/tables/reference/Arguments.html">Arguments</a></span><span class="op">(</span>na.rm <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_tvsilnxms0gecxdc6tp4(i, j, css_id) {
          var table = document.getElementById("tinytable_tvsilnxms0gecxdc6tp4");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_tvsilnxms0gecxdc6tp4(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_tvsilnxms0gecxdc6tp4");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '2', j: 1 },  ], css_id: 'tinytable_css_8h985ulw4shy33yrqzpj',}, 
          { positions: [ { i: '1', j: 1 },  ], css_id: 'tinytable_css_g1wru9os86z90xsel2o8',}, 
          { positions: [ { i: '0', j: 1 },  ], css_id: 'tinytable_css_qtwvi8hs2wcgbzp3gl0b',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_lpt520ch81gkjsraffke',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_f9h0u6rt0yseyt8hlweo',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_dxx8cpo1ela7hc7j5pp6',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_tvsilnxms0gecxdc6tp4(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_8h985ulw4shy33yrqzpj, .table th.tinytable_css_8h985ulw4shy33yrqzpj { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_g1wru9os86z90xsel2o8, .table th.tinytable_css_g1wru9os86z90xsel2o8 { text-align: right; }
      .table td.tinytable_css_qtwvi8hs2wcgbzp3gl0b, .table th.tinytable_css_qtwvi8hs2wcgbzp3gl0b { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_lpt520ch81gkjsraffke, .table th.tinytable_css_lpt520ch81gkjsraffke { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_f9h0u6rt0yseyt8hlweo, .table th.tinytable_css_f9h0u6rt0yseyt8hlweo { text-align: left; }
      .table td.tinytable_css_dxx8cpo1ela7hc7j5pp6, .table th.tinytable_css_dxx8cpo1ela7hc7j5pp6 { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_tvsilnxms0gecxdc6tp4" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mean</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">146.69</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">20.09</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># For convenience, 'modelsummary' supplies several convenience functions</span></span>
<span><span class="co"># with the argument `na.rm=TRUE` by default: Mean, Median, Min, Max, SD, Var,</span></span>
<span><span class="co"># P0, P25, P50, P75, P100, NUnique, Histogram</span></span>
<span></span>
<span><span class="co">#datasummary(hp + mpg ~ Mean + SD + Histogram, data = mtcars)</span></span>
<span></span>
<span><span class="co"># These functions also accept a 'fmt' argument which allows you to</span></span>
<span><span class="co"># round/format the results</span></span>
<span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">Mean</span> <span class="op">*</span> <span class="fu"><a href="https://dmurdoch.github.io/tables/reference/Arguments.html">Arguments</a></span><span class="op">(</span>fmt <span class="op">=</span> <span class="st">"%.3f"</span><span class="op">)</span> <span class="op">+</span> <span class="va">SD</span> <span class="op">*</span> <span class="fu"><a href="https://dmurdoch.github.io/tables/reference/Arguments.html">Arguments</a></span><span class="op">(</span>fmt <span class="op">=</span> <span class="st">"%.1f"</span><span class="op">)</span>, data <span class="op">=</span> <span class="va">mtcars</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_d25xpnat7c9cn9tmu7bp(i, j, css_id) {
          var table = document.getElementById("tinytable_d25xpnat7c9cn9tmu7bp");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_d25xpnat7c9cn9tmu7bp(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_d25xpnat7c9cn9tmu7bp");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '2', j: 1 }, { i: '2', j: 2 },  ], css_id: 'tinytable_css_b4hty60kom585dzomn8z',}, 
          { positions: [ { i: '1', j: 1 }, { i: '1', j: 2 },  ], css_id: 'tinytable_css_6mnt3wb2slj5hwyp48zz',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_xoay3quhebvholjrcizr',}, 
          { positions: [ { i: '2', j: 0 },  ], css_id: 'tinytable_css_n5t5wg7dhb4nz2ygawu6',}, 
          { positions: [ { i: '1', j: 0 },  ], css_id: 'tinytable_css_tq9456ggg33aem7t89vd',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_i8b0ov83d9009ly0ovb4',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_d25xpnat7c9cn9tmu7bp(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_b4hty60kom585dzomn8z, .table th.tinytable_css_b4hty60kom585dzomn8z { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_6mnt3wb2slj5hwyp48zz, .table th.tinytable_css_6mnt3wb2slj5hwyp48zz { text-align: right; }
      .table td.tinytable_css_xoay3quhebvholjrcizr, .table th.tinytable_css_xoay3quhebvholjrcizr { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_n5t5wg7dhb4nz2ygawu6, .table th.tinytable_css_n5t5wg7dhb4nz2ygawu6 { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_tq9456ggg33aem7t89vd, .table th.tinytable_css_tq9456ggg33aem7t89vd { text-align: left; }
      .table td.tinytable_css_i8b0ov83d9009ly0ovb4, .table th.tinytable_css_i8b0ov83d9009ly0ovb4 { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_d25xpnat7c9cn9tmu7bp" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">Mean</th>
                <th scope="col" data-row="0" data-col="2">SD</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">hp</td>
                  <td data-row="1" data-col="1">146.688</td>
                  <td data-row="1" data-col="2">68.6</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">20.091</td>
                  <td data-row="2" data-col="2">6.0</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Save your tables to a variety of output formats:</span></span>
<span><span class="va">f</span> <span class="op">&lt;-</span> <span class="va">hp</span> <span class="op">+</span> <span class="va">mpg</span> <span class="op">~</span> <span class="va">Mean</span> <span class="op">+</span> <span class="va">SD</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.html')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.tex')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.md')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.docx')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.pptx')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.jpg')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'table.png')</span></span>
<span></span>
<span><span class="co"># Display human-readable code</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'html')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'markdown')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'latex')</span></span>
<span></span>
<span><span class="co"># Return a table object to customize using a table-making package</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'tinytable')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'gt')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'kableExtra')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'flextable')</span></span>
<span><span class="co">#datasummary(f, data = mtcars, output = 'huxtable')</span></span>
<span></span>
<span><span class="co"># add_rows</span></span>
<span><span class="va">new_rows</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span><span class="op">(</span>a <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">2</span>, b <span class="op">=</span> <span class="fl">2</span><span class="op">:</span><span class="fl">3</span>, c <span class="op">=</span> <span class="fl">4</span><span class="op">:</span><span class="fl">5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/attr.html">attr</a></span><span class="op">(</span><span class="va">new_rows</span>, <span class="st">'position'</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">3</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://modelsummary.com/man/datasummary.html">datasummary</a></span><span class="op">(</span><span class="va">mpg</span> <span class="op">+</span> <span class="va">hp</span> <span class="op">~</span> <span class="va">mean</span> <span class="op">+</span> <span class="va">sd</span>, data <span class="op">=</span> <span class="va">mtcars</span>, add_rows <span class="op">=</span> <span class="va">new_rows</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_gldzicgebb61h12ty9a7(i, j, css_id) {
          var table = document.getElementById("tinytable_gldzicgebb61h12ty9a7");
          var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function spanCell_gldzicgebb61h12ty9a7(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_gldzicgebb61h12ty9a7");
        const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
        if (!targetCell) {
          console.warn(`Cell at (${i}, ${j}) not found.`);
        }

        // Get all cells that need to be removed
        const cellsToRemove = [];
        for (let r = 0; r < rowspan; r++) {
          for (let c = 0; c < colspan; c++) {
            if (r === 0 && c === 0) continue; // Skip the target cell
            const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
            if (cell) {
              cellsToRemove.push(cell);
            }
          }
        }

        // Remove all cells
        cellsToRemove.forEach(cell => cell.remove());

        // Set rowspan and colspan of the target cell if it exists
        if (targetCell) {
          targetCell.rowSpan = rowspan;
          targetCell.colSpan = colspan;
        }
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: '4', j: 1 }, { i: '4', j: 2 },  ], css_id: 'tinytable_css_af1edgyyzqe3f8pef300',}, 
          { positions: [ { i: '2', j: 1 }, { i: '3', j: 1 }, { i: '3', j: 2 }, { i: '1', j: 1 }, { i: '1', j: 2 }, { i: '2', j: 2 },  ], css_id: 'tinytable_css_ajr6vmv8oyj2or0kqk0s',}, 
          { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 },  ], css_id: 'tinytable_css_c6zr2fa3wytne820sdnm',}, 
          { positions: [ { i: '4', j: 0 },  ], css_id: 'tinytable_css_v5w8ahdructnpif5naea',}, 
          { positions: [ { i: '1', j: 0 }, { i: '2', j: 0 }, { i: '3', j: 0 },  ], css_id: 'tinytable_css_gpbus9nbkdd4ss55wt2k',}, 
          { positions: [ { i: '0', j: 0 },  ], css_id: 'tinytable_css_7t2epyk9hts5udenqysd',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_gldzicgebb61h12ty9a7(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script><style>
      /* tinytable css entries after */
      .table td.tinytable_css_af1edgyyzqe3f8pef300, .table th.tinytable_css_af1edgyyzqe3f8pef300 { text-align: right; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_ajr6vmv8oyj2or0kqk0s, .table th.tinytable_css_ajr6vmv8oyj2or0kqk0s { text-align: right; }
      .table td.tinytable_css_c6zr2fa3wytne820sdnm, .table th.tinytable_css_c6zr2fa3wytne820sdnm { text-align: right; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_v5w8ahdructnpif5naea, .table th.tinytable_css_v5w8ahdructnpif5naea { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_gpbus9nbkdd4ss55wt2k, .table th.tinytable_css_gpbus9nbkdd4ss55wt2k { text-align: left; }
      .table td.tinytable_css_7t2epyk9hts5udenqysd, .table th.tinytable_css_7t2epyk9hts5udenqysd { text-align: left; border-top: solid #d3d8dc 0.1em; border-bottom: solid #d3d8dc 0.05em; }
    </style>
<div class="container">
      <table class="table table-borderless" id="tinytable_gldzicgebb61h12ty9a7" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
<thead><tr>
<th scope="col" data-row="0" data-col="0"> </th>
                <th scope="col" data-row="0" data-col="1">mean</th>
                <th scope="col" data-row="0" data-col="2">sd</th>
              </tr></thead>
<tbody>
<tr>
<td data-row="1" data-col="0">1.00</td>
                  <td data-row="1" data-col="1">2.00</td>
                  <td data-row="1" data-col="2">4.00</td>
                </tr>
<tr>
<td data-row="2" data-col="0">mpg</td>
                  <td data-row="2" data-col="1">20.09</td>
                  <td data-row="2" data-col="2">6.03</td>
                </tr>
<tr>
<td data-row="3" data-col="0">2.00</td>
                  <td data-row="3" data-col="1">3.00</td>
                  <td data-row="3" data-col="2">5.00</td>
                </tr>
<tr>
<td data-row="4" data-col="0">hp</td>
                  <td data-row="4" data-col="1">146.69</td>
                  <td data-row="4" data-col="2">68.56</td>
                </tr>
</tbody>
</table>
</div>
<!-- hack to avoid NA insertion in last line -->
</div>
</div>


</section></section></main><!-- /main --><script id="quarto-html-after-body" type="application/javascript">
  window.document.addEventListener("DOMContentLoaded", function (event) {
    const icon = "";
    const anchorJS = new window.AnchorJS();
    anchorJS.options = {
      placement: 'right',
      icon: icon
    };
    anchorJS.add('.anchored');
    const isCodeAnnotation = (el) => {
      for (const clz of el.classList) {
        if (clz.startsWith('code-annotation-')) {                     
          return true;
        }
      }
      return false;
    }
    const onCopySuccess = function(e) {
      // button target
      const button = e.trigger;
      // don't keep focus
      button.blur();
      // flash "checked"
      button.classList.add('code-copy-button-checked');
      var currentTitle = button.getAttribute("title");
      button.setAttribute("title", "Copied!");
      let tooltip;
      if (window.bootstrap) {
        button.setAttribute("data-bs-toggle", "tooltip");
        button.setAttribute("data-bs-placement", "left");
        button.setAttribute("data-bs-title", "Copied!");
        tooltip = new bootstrap.Tooltip(button, 
          { trigger: "manual", 
            customClass: "code-copy-button-tooltip",
            offset: [0, -8]});
        tooltip.show();    
      }
      setTimeout(function() {
        if (tooltip) {
          tooltip.hide();
          button.removeAttribute("data-bs-title");
          button.removeAttribute("data-bs-toggle");
          button.removeAttribute("data-bs-placement");
        }
        button.setAttribute("title", currentTitle);
        button.classList.remove('code-copy-button-checked');
      }, 1000);
      // clear code selection
      e.clearSelection();
    }
    const getTextToCopy = function(trigger) {
        const codeEl = trigger.previousElementSibling.cloneNode(true);
        for (const childEl of codeEl.children) {
          if (isCodeAnnotation(childEl)) {
            childEl.remove();
          }
        }
        return codeEl.innerText;
    }
    const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
      text: getTextToCopy
    });
    clipboard.on('success', onCopySuccess);
    if (window.document.getElementById('quarto-embedded-source-code-modal')) {
      const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
        text: getTextToCopy,
        container: window.document.getElementById('quarto-embedded-source-code-modal')
      });
      clipboardModal.on('success', onCopySuccess);
    }
      var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
      var mailtoRegex = new RegExp(/^mailto:/);
        var filterRegex = new RegExp('/' + window.location.host + '/');
      var isInternal = (href) => {
          return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
      }
      // Inspect non-navigation links and adorn them if external
     var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
      for (var i=0; i<links.length; i++) {
        const link = links[i];
        if (!isInternal(link.href)) {
          // undo the damage that might have been done by quarto-nav.js in the case of
          // links that we want to consider external
          if (link.dataset.originalHref !== undefined) {
            link.href = link.dataset.originalHref;
          }
        }
      }
    function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
      const config = {
        allowHTML: true,
        maxWidth: 500,
        delay: 100,
        arrow: false,
        appendTo: function(el) {
            return el.parentElement;
        },
        interactive: true,
        interactiveBorder: 10,
        theme: 'quarto',
        placement: 'bottom-start',
      };
      if (contentFn) {
        config.content = contentFn;
      }
      if (onTriggerFn) {
        config.onTrigger = onTriggerFn;
      }
      if (onUntriggerFn) {
        config.onUntrigger = onUntriggerFn;
      }
      window.tippy(el, config); 
    }
    const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
    for (var i=0; i<noterefs.length; i++) {
      const ref = noterefs[i];
      tippyHover(ref, function() {
        // use id or data attribute instead here
        let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
        try { href = new URL(href).hash; } catch {}
        const id = href.replace(/^#\/?/, "");
        const note = window.document.getElementById(id);
        if (note) {
          return note.innerHTML;
        } else {
          return "";
        }
      });
    }
    const xrefs = window.document.querySelectorAll('a.quarto-xref');
    const processXRef = (id, note) => {
      // Strip column container classes
      const stripColumnClz = (el) => {
        el.classList.remove("page-full", "page-columns");
        if (el.children) {
          for (const child of el.children) {
            stripColumnClz(child);
          }
        }
      }
      stripColumnClz(note)
      if (id === null || id.startsWith('sec-')) {
        // Special case sections, only their first couple elements
        const container = document.createElement("div");
        if (note.children && note.children.length > 2) {
          container.appendChild(note.children[0].cloneNode(true));
          for (let i = 1; i < note.children.length; i++) {
            const child = note.children[i];
            if (child.tagName === "P" && child.innerText === "") {
              continue;
            } else {
              container.appendChild(child.cloneNode(true));
              break;
            }
          }
          if (window.Quarto?.typesetMath) {
            window.Quarto.typesetMath(container);
          }
          return container.innerHTML
        } else {
          if (window.Quarto?.typesetMath) {
            window.Quarto.typesetMath(note);
          }
          return note.innerHTML;
        }
      } else {
        // Remove any anchor links if they are present
        const anchorLink = note.querySelector('a.anchorjs-link');
        if (anchorLink) {
          anchorLink.remove();
        }
        if (window.Quarto?.typesetMath) {
          window.Quarto.typesetMath(note);
        }
        if (note.classList.contains("callout")) {
          return note.outerHTML;
        } else {
          return note.innerHTML;
        }
      }
    }
    for (var i=0; i<xrefs.length; i++) {
      const xref = xrefs[i];
      tippyHover(xref, undefined, function(instance) {
        instance.disable();
        let url = xref.getAttribute('href');
        let hash = undefined; 
        if (url.startsWith('#')) {
          hash = url;
        } else {
          try { hash = new URL(url).hash; } catch {}
        }
        if (hash) {
          const id = hash.replace(/^#\/?/, "");
          const note = window.document.getElementById(id);
          if (note !== null) {
            try {
              const html = processXRef(id, note.cloneNode(true));
              instance.setContent(html);
            } finally {
              instance.enable();
              instance.show();
            }
          } else {
            // See if we can fetch this
            fetch(url.split('#')[0])
            .then(res => res.text())
            .then(html => {
              const parser = new DOMParser();
              const htmlDoc = parser.parseFromString(html, "text/html");
              const note = htmlDoc.getElementById(id);
              if (note !== null) {
                const html = processXRef(id, note);
                instance.setContent(html);
              } 
            }).finally(() => {
              instance.enable();
              instance.show();
            });
          }
        } else {
          // See if we can fetch a full url (with no hash to target)
          // This is a special case and we should probably do some content thinning / targeting
          fetch(url)
          .then(res => res.text())
          .then(html => {
            const parser = new DOMParser();
            const htmlDoc = parser.parseFromString(html, "text/html");
            const note = htmlDoc.querySelector('main.content');
            if (note !== null) {
              // This should only happen for chapter cross references
              // (since there is no id in the URL)
              // remove the first header
              if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
                note.children[0].remove();
              }
              const html = processXRef(null, note);
              instance.setContent(html);
            } 
          }).finally(() => {
            instance.enable();
            instance.show();
          });
        }
      }, function(instance) {
      });
    }
        let selectedAnnoteEl;
        const selectorForAnnotation = ( cell, annotation) => {
          let cellAttr = 'data-code-cell="' + cell + '"';
          let lineAttr = 'data-code-annotation="' +  annotation + '"';
          const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
          return selector;
        }
        const selectCodeLines = (annoteEl) => {
          const doc = window.document;
          const targetCell = annoteEl.getAttribute("data-target-cell");
          const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
          const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
          const lines = annoteSpan.getAttribute("data-code-lines").split(",");
          const lineIds = lines.map((line) => {
            return targetCell + "-" + line;
          })
          let top = null;
          let height = null;
          let parent = null;
          if (lineIds.length > 0) {
              //compute the position of the single el (top and bottom and make a div)
              const el = window.document.getElementById(lineIds[0]);
              top = el.offsetTop;
              height = el.offsetHeight;
              parent = el.parentElement.parentElement;
            if (lineIds.length > 1) {
              const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
              const bottom = lastEl.offsetTop + lastEl.offsetHeight;
              height = bottom - top;
            }
            if (top !== null && height !== null && parent !== null) {
              // cook up a div (if necessary) and position it 
              let div = window.document.getElementById("code-annotation-line-highlight");
              if (div === null) {
                div = window.document.createElement("div");
                div.setAttribute("id", "code-annotation-line-highlight");
                div.style.position = 'absolute';
                parent.appendChild(div);
              }
              div.style.top = top - 2 + "px";
              div.style.height = height + 4 + "px";
              div.style.left = 0;
              let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
              if (gutterDiv === null) {
                gutterDiv = window.document.createElement("div");
                gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
                gutterDiv.style.position = 'absolute';
                const codeCell = window.document.getElementById(targetCell);
                const gutter = codeCell.querySelector('.code-annotation-gutter');
                gutter.appendChild(gutterDiv);
              }
              gutterDiv.style.top = top - 2 + "px";
              gutterDiv.style.height = height + 4 + "px";
            }
            selectedAnnoteEl = annoteEl;
          }
        };
        const unselectCodeLines = () => {
          const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
          elementsIds.forEach((elId) => {
            const div = window.document.getElementById(elId);
            if (div) {
              div.remove();
            }
          });
          selectedAnnoteEl = undefined;
        };
          // Handle positioning of the toggle
      window.addEventListener(
        "resize",
        throttle(() => {
          elRect = undefined;
          if (selectedAnnoteEl) {
            selectCodeLines(selectedAnnoteEl);
          }
        }, 10)
      );
      function throttle(fn, ms) {
      let throttle = false;
      let timer;
        return (...args) => {
          if(!throttle) { // first call gets through
              fn.apply(this, args);
              throttle = true;
          } else { // all the others get throttled
              if(timer) clearTimeout(timer); // cancel #2
              timer = setTimeout(() => {
                fn.apply(this, args);
                timer = throttle = false;
              }, ms);
          }
        };
      }
        // Attach click handler to the DT
        const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
        for (const annoteDlNode of annoteDls) {
          annoteDlNode.addEventListener('click', (event) => {
            const clickedEl = event.target;
            if (clickedEl !== selectedAnnoteEl) {
              unselectCodeLines();
              const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
              if (activeEl) {
                activeEl.classList.remove('code-annotation-active');
              }
              selectCodeLines(clickedEl);
              clickedEl.classList.add('code-annotation-active');
            } else {
              // Unselect the line
              unselectCodeLines();
              clickedEl.classList.remove('code-annotation-active');
            }
          });
        }
    const findCites = (el) => {
      const parentEl = el.parentElement;
      if (parentEl) {
        const cites = parentEl.dataset.cites;
        if (cites) {
          return {
            el,
            cites: cites.split(' ')
          };
        } else {
          return findCites(el.parentElement)
        }
      } else {
        return undefined;
      }
    };
    var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
    for (var i=0; i<bibliorefs.length; i++) {
      const ref = bibliorefs[i];
      const citeInfo = findCites(ref);
      if (citeInfo) {
        tippyHover(citeInfo.el, function() {
          var popup = window.document.createElement('div');
          citeInfo.cites.forEach(function(cite) {
            var citeDiv = window.document.createElement('div');
            citeDiv.classList.add('hanging-indent');
            citeDiv.classList.add('csl-entry');
            var biblioDiv = window.document.getElementById('ref-' + cite);
            if (biblioDiv) {
              citeDiv.innerHTML = biblioDiv.innerHTML;
            }
            popup.appendChild(citeDiv);
          });
          return popup.innerHTML;
        });
      }
    }
  });
  </script><nav class="page-navigation"><div class="nav-page nav-page-previous">
      <a href="../man/modelplot.html" class="pagination-link" aria-label="`modelplot`">
        <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><code>modelplot</code></span>
      </a>          
  </div>
  <div class="nav-page nav-page-next">
      <a href="../man/datasummary_skim.html" class="pagination-link" aria-label="`datasummary_skim`">
        <span class="nav-page-text"><code>datasummary_skim</code></span> <i class="bi bi-arrow-right-short"></i>
      </a>
  </div>
</nav>
</div> <!-- /content -->



</body></html>